package com.platform.hjt.sys.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hjt.tools.dao.Page;
import com.hjt.tools.dao.PropertyFilter;
import com.platform.hjt.base.controller.BaseController;
import com.platform.hjt.base.controller.ReturnBody;

import com.platform.hjt.sys.model.SysState;
import com.platform.hjt.sys.service.SysStateService;

@Controller
@RequestMapping(value="/sysState")
public class SysStateController extends BaseController{

	@Resource
	private SysStateService sysStateService;
	
	@RequestMapping(value="/sysState_list.html")
	public String sysStateListPage(){
		return "page/admin/sysState/sysState_list";
	}
	
	@RequestMapping(value="/sysState_list.do")
	@ResponseBody
	public Page<SysState> sysStateListDo(String tableName, String tableColumn, Page<SysState>page){
		List<PropertyFilter>  propertyFilterList = PropertyFilter.buildFromHttpRequest(getRequest());
		propertyFilterList.add(new PropertyFilter("EQS_tableName", tableName));
		propertyFilterList.add(new PropertyFilter("EQS_tableColumn", tableColumn));
		propertyFilterList.add(new PropertyFilter("EQS_sysCompanyInfo.sysCompanyInfoId", getSessionSysCompanyInfo().getSysCompanyInfoId()));
		propertyFilterList.add(new PropertyFilter("EQB_isDel", "false"));
		return sysStateService.getSysStateList(page, propertyFilterList);
	}
	
	@RequestMapping(value="/sysState_edit.html")
	public String sysStateEditPage(HttpServletRequest request, Model model, String id){
		if(StringUtils.isNotBlank(id)){
			model.addAttribute("sysState", sysStateService.getSysState("sysStateId", id));
		}
		
		return "page/admin/sysState/sysState_edit";
	}
	
	@RequestMapping(value="/sysState_detail_{id}.html")
	public String sysStateDetailPage(Model model, @PathVariable String id){
		model.addAttribute("sysState", sysStateService.getSysState("sysStateId", id));
		return "page/admin/sysState/sysState_detail";
	}
	
	@RequestMapping(value="/sysState_edit.do")
	@ResponseBody
	public ReturnBody sysStateEditDo(@Valid @ModelAttribute("sysState") SysState sysState, BindingResult result){
		if(result.hasErrors()){
			return new ReturnBody(false, result.getAllErrors().get(0).getDefaultMessage());
		}
		
		
		return sysStateService.saveSysState(sysState);
	}
	
	@RequestMapping(value="/sysState_del_{id}.do")
	@ResponseBody
	public ReturnBody sysStateDelDo(@PathVariable String id){
		return sysStateService.delSysState(new SysState(id));
	}
	
	
}
